<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="区域" prop="region">
        <el-select clearable v-model="queryParams.region" placeholder="请选择">
          <el-option v-for="item in HL_SHNDZ_list" :key="item.Code" :label="item.Name" :value="item.Code">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="名称" prop="PerName">
        <el-input v-model="queryParams.PerName" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['administrative:holidaymangement:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['administrative:holidaymangement:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['administrative:holidaymangement:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['administrative:holidaymangement:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="holidaymangementList" @selection-change="handleSelectionChange" height="500">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column prop="year" label="年度">
      </el-table-column>
      <el-table-column prop="perCode" label="工号">
      </el-table-column>
      <el-table-column prop="perName" label="姓名">
      </el-table-column>
      <el-table-column prop="holidayTypeName" label="假别">
        <template slot-scope="scope">
          <el-tag>{{ scope.row.holidayTypeName }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="dtstart" label="开始日期" width="130">
      </el-table-column>
      <el-table-column prop="dtend" label="结束日期" width="130">
      </el-table-column>
      <el-table-column prop="days" label="天数">
      </el-table-column>
      <el-table-column prop="air" label="机票">
      </el-table-column>
      <el-table-column prop="dlper" label="职务代理人" width="180">
      </el-table-column>
      <el-table-column prop="remark" label="备注" width="300">
      </el-table-column>
      <el-table-column prop="operatorname" label="建档人">
      </el-table-column>
      <el-table-column prop="createtimes" label="建档时间" width="200">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['datalist:holidaymangement:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['datalist:holidaymangement:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改假期管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="650px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="年度" prop="year">
              <el-input v-model="form.year" placeholder="请输入年度" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工号" prop="perCode">
              <el-input v-model="form.perCode" placeholder="请输入工号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="假别" prop="holidayTypeName">
              <el-select clearable v-model="form.holidayTypeName" placeholder="请选择假别">
                <el-option v-for="item in SysHolidayType_list" :key="item.Code" :label="item.Name" :value="item.Code">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="天数" prop="days">
              <el-input v-model="form.days" placeholder="请输入天数" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="开始日期" prop="dtstart">
              <el-date-picker v-model="form.dtstart" type="date" placeholder="选择日期" format="yyyy-MM-dd"
                value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结束日期" prop="dtend">
              <el-date-picker v-model="form.dtend" type="date" placeholder="选择日期" format="yyyy-MM-dd"
                value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="出发点" prop="departure">
              <el-input v-model="form.departure" placeholder="出发点" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="抵达点" prop="arrival">
              <el-input v-model="form.arrival" placeholder="抵达点" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="机票" prop="air">
              <el-input v-model="form.air" placeholder="请输入机票/张" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职务代理人" prop="dlper">
              <el-input v-model="form.dlper" placeholder="请输入职务代理人" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="原假别" prop="holidayTypeName">
              <el-select clearable v-model="form.holidayTypeName" placeholder="请选择假别">
                <el-option v-for="item in SysHolidayType_list" :key="item.Code" :label="item.Name" :value="item.Code">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <p style="height: 100%;width: 100%; display: flex;align-items: center;color: red;margin-left: 20px;">销假时请选择原假别
            </p>
          </el-col>
        </el-row>



        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
</div>
</template>

<script>












import {
  listHolidaymangement, getHolidaymangement, delHolidaymangement,
  addHolidaymangement, updateHolidaymangement
} from "@/api/administrative/holidaymangement";
import {
  Get_public_SysLevel, Get_public_SysPosition,
  Get_public_SysHolidayType, Get_public_HL_SHNDZ
} from "@/api/publics/index";

export default {
  name: "Holidaymangement",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 假期管理表格数据
      holidaymangementList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        fbillno: null,
        hiid: null,
        holidaytype: null,
        dtstart: null,
        dtend: null,
        days: null,
        air: null,
        dlper: null,
        remark: null,
        audit: null,
        operator: null,
        createtime: null,
        updatetime: null,
        currentaudit: null,
        starttype: null,
        endtype: null,
        adddeletype: null,
        company: null,
        xjtype: null,
        PerName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 职称菜单
      SysLevel_list: [],
      // 职称菜单
      SysPosition_list: [],
      // 职称菜单
      SysHolidayType_list: [],
      // 职称菜单
      HL_SHNDZ_list: [],
    };
  },
  created() {
    this.getList();
    this.GetInit();
  },
  methods: {
    GetInit() {
      Get_public_SysLevel().then((res) => {
        this.SysLevel_list = res.data;
        // console.log("res", res.data);
      });
      Get_public_SysPosition().then((res) => {
        this.SysPosition_list = res.data;
        // console.log("res", res.data);
      });
      Get_public_SysHolidayType().then((res) => {
        this.SysHolidayType_list = res.data;
        console.log("res", res.data);
      });
      Get_public_HL_SHNDZ().then((res) => {
        this.HL_SHNDZ_list = res.data;
        // console.log("res", res.data);
      });
    },
    /** 查询假期管理列表 */
    getList() {
      this.loading = true;
      listHolidaymangement(this.queryParams).then(response => {
        this.holidaymangementList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fbillno: null,
        hiid: null,
        holidaytype: null,
        dtstart: null,
        dtend: null,
        days: null,
        air: null,
        dlper: null,
        remark: null,
        audit: null,
        operator: null,
        createtime: null,
        updatetime: null,
        currentaudit: null,
        starttype: null,
        endtype: null,
        adddeletype: null,
        company: null,
        xjtype: null,
        PerName: null,
        departure: null,
        arrival: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加假期管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getHolidaymangement(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改假期管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHolidaymangement(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHolidaymangement(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除假期管理编号为"' + ids + '"的数据项？').then(function () {
        return delHolidaymangement(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('datalist/holidaymangement/export', {
        ...this.queryParams
      }, `holidaymangement_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
